param(
    [string]$Input = "..\examples\arithmetic.mlir",
    [string]$OutputDir = "..\build"
)

if (-not (Test-Path $OutputDir)) {
    New-Item -ItemType Directory -Path $OutputDir | Out-Null
}

$canonicalPath = Join-Path $OutputDir "canonical.mlir"
$llvmPath = Join-Path $OutputDir "lowered.ll"

Write-Host ">> mlir-opt --convert-scf-to-std --convert-func-to-llvm $Input -o $canonicalPath"
mlir-opt --convert-scf-to-std --convert-func-to-llvm $Input -o $canonicalPath

Write-Host ">> mlir-translate --mlir-to-llvmir $canonicalPath -o $llvmPath"
mlir-translate --mlir-to-llvmir $canonicalPath -o $llvmPath

Write-Host "生成的 LLVM IR 位于 $llvmPath"
